package cn.dida.dao;

import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import cn.dida.model.RgnRegion;

/**
 * <p>区域 数据交互类</p>
 * @author lisha
 * @date 2016-11-15 10:33
 * */
@Repository
public class RgnRegionDao extends DaoBase {

	/**
	 * 根据条件获取区域信息
	 * @param parentId 父节点id
	 * @return List<rgnRegion> 区域信息列表
	 * @date 2016-11-15 10:38
	 * */
	public List<RgnRegion> query(Integer parentId) {
        Object[] args = {};
        StringBuffer sqlQueryResult = new StringBuffer("select * from rgn_region where is_show = ? ");

            args = ArrayUtils.add(args, 1);
            if(parentId != null){
                StringBuffer sqlWhere = new StringBuffer(" and parentId = ?");
                args = ArrayUtils.add(args, parentId);
                sqlQueryResult.append(sqlWhere);
            }

        
        // 查询记录
            sqlQueryResult.append("  order by id asc");
        List<RgnRegion> result = jdbcTemplate.query(sqlQueryResult.toString(), args, new BeanPropertyRowMapper<>(RgnRegion.class));
        return result;
    }
}
